package com.ai.platform.spider.download;

import com.ai.platform.spider.utils.SpiderUtil;

import java.io.Serializable;

/**
 * 功能描述 返回对象
 * 创建者 yeyingsheng
 * 创建时间 2018年06月27日
 */
public class Response implements Serializable{

    private static final long serialVersionUID = -9068800067277456934L;

    public Response(Request request) {
        this.request = request;
    }

    public Response(Request request, int statusCode, String statusDesc) {
        this.request = request;
        this.statusCode = statusCode;
        this.statusDesc = statusDesc;
    }

    private Request request;
    private int statusCode;
    private String statusDesc;
    //----- 几个常用的header -----
    private String mimeType;
    private String charset;
    private String location;
    //------------------------
    private byte[] body;
    private String bodyStr;// 默认是null
    //------------------------
    private Throwable exception;

    public Request getRequest() {
        return request;
    }
    public void setRequest(Request request) {
        this.request = request;
    }
    public int getStatusCode() {
        return statusCode;
    }
    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }
    public String getStatusDesc() {
        return statusDesc;
    }
    public void setStatusDesc(String statusDesc) {
        this.statusDesc = statusDesc;
    }
    public String getMimeType() {
        return mimeType;
    }
    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }
    public String getCharset() {
        return charset;
    }
    public void setCharset(String charset) {
        this.charset = charset;
    }
    public byte[] getBody() {
        return body;
    }
    public void setBody(byte[] body) {
        this.body = body;
    }
    public String getLocation() {
        return location;
    }
    public void setLocation(String location) {
        this.location = location;
    }

    public String getBodyStr() {
        if (bodyStr == null && body != null) {
            bodyStr = SpiderUtil.byteToStringForHtml(body, charset);
        }
        return bodyStr;
    }

    public void setBodyStr(String bodyStr) {
        this.bodyStr = bodyStr;
    }

    public Throwable getException() {
        return exception;
    }

    public void setException(Throwable exception) {
        this.exception = exception;
    }


}
